<template>
	<view class="user">
		<view class="user-dl">
			<view class="user-header" v-if="token">
				<image src="../../static/images/icon/head04.png"></image>
				<view class="">
					用户昵称
				</view>
			</view>
			<view class="user-header-wdl" v-else>
				<image src="../../static/images/icon/head04.png"></image>
				<view class="">
					<view class="">
						未登录
					</view>
					<text @click="toLogin()">点击登录账号</text>
				</view>
			</view>
			<view class="user-wddd">
				<text>我的订单</text>
				<text @click="handleCkqb">查看全部></text>
			</view>
			<view class="index-nav">
				<view class="nav-box" @click="handleDzf">
					<view class="num" v-if="token&&unPay">{{unPay}}</view>
					<image src="../../static/images/icon/toPay.png"></image>
					<view>
						待支付
					</view>
				</view>
				<view class="nav-box" @click="handleDfh">
					<view class="num" v-if="token&&num">{{num}}</view>
					<image src="../../static/images/icon/toDelivery.png"></image>
					<view>
						待发货
					</view>
				</view>
				<view class="nav-box" @click="handleDsh">
					<view class="num" v-if="token&&consignment">{{consignment}}</view>
					<image src="../../static/images/icon/toTake.png"></image>
					<view>
						待收货
					</view>
				</view>
				<view class="nav-box" @click="handleYwc">
					<view class="num" v-if="token&&confirm">{{confirm}}</view>
					<image src="../../static/images/icon/toComment.png"></image>
					<view>
						已完成
					</view>
				</view>
			</view>
			<view class="user-col">
				<view class="user-col-box" @click="handleXsth">
					<view class="col-box-num" v-if="token">
						{{like}}
					</view>
					<view class="col-box-num" v-else>
						--
					</view>
					<view class="col-box-p">
						我的收藏
					</view>
				</view>
				<view class="user-col-box">
					<view class="col-box-num" v-if="token">
						5
					</view>
					<view class="col-box-num" v-else>
						--
					</view>
					<view class="col-box-p">
						我的消息
					</view>
				</view>
				<view class="user-col-box">
					<view class="col-box-num" v-if="token">
						3
					</view>
					<view class="col-box-num" v-else>
						--
					</view>
					<view class="col-box-p">
						我的足迹
					</view>
				</view>
			</view>
			<view class="user-foot">
				<view class="user-foot-box">
					<image src="../../static/images/icon/promotion.png"></image>
					<text>分销中心</text>
					<image src="../../static/images/icon/more.png"></image>
				</view>
				<view class="user-foot-box">
					<image src="../../static/images/icon/promotion.png"></image>
					<text>领券中心</text>
					<image src="../../static/images/icon/more.png"></image>
				</view>
				<view class="user-foot-box">
					<image src="../../static/images/icon/promotion.png"></image>
					<text>我的优惠卷</text>
					<image src="../../static/images/icon/more.png"></image>
				</view>
				<view class="user-foot-box" @click="handleAddress">
					<image src="../../static/images/icon/promotion.png"></image>
					<text>收货地址</text>
					<image src="../../static/images/icon/more.png"></image>
				</view>
			</view>
			<view class="user-btn" v-if="token">
				<button @click="handleTc">退出登录</button>
			</view>
			<!-- <button @click="toLogin()">登录</button> -->
		</view>
	</view>
</template>
<script>
	var http = require("../../utils/http");
	export default {
		data() {
			return {
				like: 0,
				token: "",
				// 代发货
				num:"",
				// 待收货
				consignment:'',
				// 未支付
				unPay:'',
				// 已完成
				confirm:'',

			}
		},
		onShow() {
			this.token = uni.getStorageSync('token')
			// if (token) {
			// 	http.request({
			// 		url: "/p/myOrder/orderCount",
			// 		method: "get",
			// 		data: {},
			// 		callBack: res => {
			// 			this.num = res.allCount
			// 			// console.log(this.swiperList, "232431");
			// 		}
			// 	})
			// }
		},
		onLoad() {
			http.request({
				url: "/p/myOrder/orderCount",
				method: "get",
				data: {},
				callBack: res => {
					this.num = res.payed
					this.consignment = res.consignment
					this.unPay=res.unPay
					this.confirm=res.confirm
					// console.log(this.swiperList, "232431");
				}
			})
			http.request({
				url: "/p/user/collection/count",
				method: "get",
				data: {},
				callBack: res => {
					this.like = res
					// console.log(this.swiperList, "232431");
				}
			})
		},
		methods: {
			toLogin: function() {
				uni.navigateTo({
					url: "../accountLogin/accountLogin"
				})
			},
			// 收货地址
			handleAddress() {
				uni.navigateTo({
					url: '/pages/delivery-address/delivery-address'
				})
			},
			// 查看全部
			handleCkqb() {
				const sts = 0
				uni.navigateTo({
					url: `/pages/orderList/orderList?sts=${sts}`
				});
			},
			handleDzf() {
				const sts = 1
				uni.navigateTo({
					url: `/pages/orderList/orderList?sts=${sts}`
				});
			},
			handleDfh() {
				const sts = 2
				uni.navigateTo({
					url: `/pages/orderList/orderList?sts=${sts}`
				});
			},
			handleDsh() {
				const sts = 3
				uni.navigateTo({
					url: `/pages/orderList/orderList?sts=${sts}`
				});
			},
			handleYwc() {
				const sts = 5
				uni.navigateTo({
					url: `/pages/orderList/orderList?sts=${sts}`
				});
			},
			handleTc() {
				uni.removeStorageSync('token');
				this.token = uni.getStorageSync('token')
				uni.showLoading({
					title: "退出成功",
					icon: 'none'
				})
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/index/index'
					});
				}, 1000)
			},
			handleXsth() {
				const sts = 5
				uni.navigateTo({
					url: `/pages/prod-classify/prod-classify?sts=${sts}`
				})
			},
			
		}
	}
</script>
<style lang="scss" scoped>
	.user::v-deep {
		.user-header {
			background-color: #fff;
			padding: 20px;
			text-align: center;
			font-weight: 700;
			font-size: 16px;

			image {
				width: 80px;
				height: 80px;
				margin-bottom: 10upx;
			}

			margin-bottom: 10px;
		}

		.user-wddd {
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			padding: 10px;

			text {
				&:nth-child(1) {
					font-size: 14px;
					font-weight: 900;
				}

				&:nth-child(2) {
					font-size: 12px;
					color: #999;
				}

			}
		}

		.index-nav {
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			cursor: pointer;
			padding: 10px 0;

			.nav-box {
				position: relative;
				width: 25%;
				display: flex;
				flex-direction: column;
				text-align: center;
				align-items: center;
				font-size: 12px;

				.num {
					position: absolute;
					right: 21px;
					z-index: 11;
					color: #f00;
					border-radius: 50%;
					border: 1px solid #f00;
					top: -9px;
					background: #fff;
					height: 22px;
					width: 22px;
					line-height: 22px
				}

				image {
					width: 37px;
					height: 37px;
					margin-bottom: 10upx;
				}
			}
		}

		.user-col {
			margin-top: 10px;
			background-color: #fff;
			display: flex;
			justify-content: space-around;

			.user-col-box {
				text-align: center;
				padding: 16px 0;

				.col-box-num {
					color: #3a86c9;
					font-weight: 700;
					margin-bottom: 10upx;
				}
			}
		}

		.user-foot {
			background-color: #fff;
			margin-top: 10px;

			.user-foot-box {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 10px;
				border-bottom: 1upx solid #eaeaea;

				image {
					width: 25px;
					height: 25px;

					&:last-child {
						width: 12px;
						height: 12px;
					}
				}

				text {
					display: inline-block;
					width: 84%;
				}
			}
		}

		.user-btn {
			margin-top: 10px;
			text-align: center;

			button {
				width: 116px;
				color: #fff;
				background-color: #f00;
				border-radius: 6px;
				font-size: 16px;
			}
		}

		.user-header-wdl {
			background-color: #fff;
			padding: 20px;

			image {
				width: 80px;
				height: 80px;
				margin-bottom: 10upx;
				vertical-align: middle;
			}

			>view {
				vertical-align: middle;
				display: inline-block;
				margin-left: 10px;

				view {
					margin-bottom: 10px;
					font-size: 16px;
				}

				text {
					font-size: 12px;
					color: #999;
				}
			}

		}
	}
</style>